//
//  CardSettingView.swift
//  TLCLockDemo
//
//  Created by run on 2024/7/24.
//

import SwiftUI
import TLCLock

struct CardSettingView: View {


    let device: LockDevice

    @State var cardType: CardType = .all

    var body: some View {
        
        VStack {
            YxrPicker(
                title: "选择卡类型", selectValue: $cardType,
                options: [
                    ("所有类型", .all),
                    ("M1卡", .m1),
                    ("CPU卡", .cpu),
                    ("身份证卡", .identifier),
                    ("关闭读头", .close),
                ]
            )
            
            YxrConfirmView(title: "确定") {
                Log.info("当前的卡类型：\(cardType.rawValue)")
                cardSetting(cardType: cardType)
            }
            
            LogView()
        }
        
        .yxrNavigationTitle("门卡设置")
    }

    func cardSetting(cardType: CardType) {
        guard let lockKey = Server.getSecret(device.macAddress) else {
            showToast("没有lockKey")
            return
        }
        lockTask(desc: "门卡设置") {
            await device.cardSetting(cardType, lockKey: lockKey, trackId: Server.testTrackId)
        }
    }
}
